/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package swingcalc;

import javax.swing.JTextField;

/**
 *
 * @author Administrator
 */
public class SwingCalc extends javax.swing.JFrame {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
     * Creates new form SwingCalc
     */
    private double xdouble;
    private String resultdouble;

    public SwingCalc() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextResult = new javax.swing.JTextField();
        jTextResult.setHorizontalAlignment(JTextField.RIGHT);
        jButto9 = new javax.swing.JButton();
        jButtonClear = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButtonRuslt = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton0 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButtonDiv = new javax.swing.JButton();
        jButtonadd = new javax.swing.JButton();
        jButtonsub = new javax.swing.JButton();
        jButtonMul = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("计算器   by java dev");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                formMouseMoved(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTextResult.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jTextResult.setText("0");
        jTextResult.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jTextResult.setDisabledTextColor(new java.awt.Color(51, 51, 255));
        jTextResult.setEnabled(false);
        jTextResult.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jTextResultAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
        });
        jTextResult.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextResultActionPerformed(evt);
            }
        });
        getContentPane().add(jTextResult, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 340, 50));

        jButto9.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButto9.setText("9");
        jButto9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButto9ActionPerformed(evt);
            }
        });
        getContentPane().add(jButto9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, 80, 40));

        jButtonClear.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButtonClear.setText("清除");
        jButtonClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonClearActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonClear, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 70, 80, 40));

        jButton8.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButton8.setText("8");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 120, 80, 40));

        jButtonRuslt.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButtonRuslt.setText("=");
        jButtonRuslt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRusltActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonRuslt, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 220, 80, 40));

        jButton7.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButton7.setText("7");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 120, 80, 40));

        jButton6.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButton6.setText("6");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 170, 80, 40));

        jButton3.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButton3.setText("3");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 220, 80, 40));

        jButton0.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButton0.setText("0");
        jButton0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton0ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton0, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 80, 40));

        jButton5.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButton5.setText("5");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 170, 80, 40));

        jButton11.setFont(new java.awt.Font("瀹嬩綋", 0, 10)); // NOI18N
        jButton11.setText("jButton1");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton11, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 170, 80, 40));

        jButton2.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButton2.setText("2");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 220, 80, 40));

        jButton1.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButton1.setText("1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton1KeyPressed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 220, 80, 40));

        jButton4.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButton4.setText("4");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 170, 80, 40));

        jButtonDiv.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButtonDiv.setText("/");
        jButtonDiv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDivActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonDiv, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 70, 80, 40));

        jButtonadd.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButtonadd.setText("+");
        jButtonadd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonaddActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonadd, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 170, 80, 40));

        jButtonsub.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButtonsub.setText("-");
        jButtonsub.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonsubActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonsub, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 120, 80, 40));

        jButtonMul.setFont(new java.awt.Font("瀹嬩綋", 0, 24)); // NOI18N
        jButtonMul.setText("*");
        jButtonMul.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMulActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonMul, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 70, 80, 40));

        setSize(new java.awt.Dimension(388, 304));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        if (!"0".equals(jTextResult.getText())) {

            jTextResult.setText(jTextResult.getText() + jButton5.getText());
        } else {
            jTextResult.setText("");
            jTextResult.setText(jTextResult.getText() + jButton5.getText());
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        if (!"0".equals(jTextResult.getText())) {

            jTextResult.setText(jTextResult.getText() + jButton2.getText());
        } else {
            jTextResult.setText("");
            jTextResult.setText(jTextResult.getText() + jButton2.getText());
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        if (!"0".equals(jTextResult.getText())) {

            jTextResult.setText(jTextResult.getText() + jButton3.getText());
        } else {
            jTextResult.setText("");
            jTextResult.setText(jTextResult.getText() + jButton3.getText());
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        if (!"0".equals(jTextResult.getText())) {

            jTextResult.setText(jTextResult.getText() + jButton4.getText());
        } else {
            jTextResult.setText("");
            jTextResult.setText(jTextResult.getText() + jButton4.getText());
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1KeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1KeyPressed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:

        if (!"0".equals(jTextResult.getText())) {

            jTextResult.setText(jTextResult.getText() + jButton1.getText());
        } else {
            jTextResult.setText("");
            jTextResult.setText(jTextResult.getText() + jButton1.getText());
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextResultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextResultActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_jTextResultActionPerformed

    private void jTextResultAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_jTextResultAncestorAdded
        // TODO add your handling code here:


    }//GEN-LAST:event_jTextResultAncestorAdded

    private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
        // TODO add your handling code here:

    }//GEN-LAST:event_formMouseMoved

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
        if (!"0".equals(jTextResult.getText())) {

            jTextResult.setText(jTextResult.getText() + jButton6.getText());
        } else {
            jTextResult.setText("");
            jTextResult.setText(jTextResult.getText() + jButton6.getText());
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        // TODO add your handling code here:
        if (!"0".equals(jTextResult.getText())) {

            jTextResult.setText(jTextResult.getText() + jButton7.getText());
        } else {
            jTextResult.setText("");
            jTextResult.setText(jTextResult.getText() + jButton7.getText());
        }
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        // TODO add your handling code here:
        if (!"0".equals(jTextResult.getText())) {

            jTextResult.setText(jTextResult.getText() + jButton8.getText());
        } else {
            jTextResult.setText("");
            jTextResult.setText(jTextResult.getText() + jButton8.getText());
        }
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButto9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButto9ActionPerformed
        // TODO add your handling code here:
        if (!"0".equals(jTextResult.getText())) {

            jTextResult.setText(jTextResult.getText() + jButto9.getText());
        } else {
            jTextResult.setText("");
            jTextResult.setText(jTextResult.getText() + jButto9.getText());
        }
    }//GEN-LAST:event_jButto9ActionPerformed

    private void jButton0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton0ActionPerformed
        // TODO add your handling code here:
        jTextResult.setText(jTextResult.getText() + jButton0.getText());
    }//GEN-LAST:event_jButton0ActionPerformed

    private void jButtonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonClearActionPerformed
        // TODO add your handling code here:
        jTextResult.setText("0");
    }//GEN-LAST:event_jButtonClearActionPerformed

    private void jButtonaddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonaddActionPerformed
        // TODO add your handling code here:
        resultdouble = jButtonadd.getText();

        xdouble = Double.parseDouble(jTextResult.getText());
        jTextResult.setText(" ");

    }//GEN-LAST:event_jButtonaddActionPerformed
//涓昏鐨勮绠楁柟娉�
    private void jButtonRusltActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRusltActionPerformed
        // TODO add your handling code here:
        double result;
        switch (resultdouble) {
            case "+":
                result = CalcUtil.add(xdouble, Double.parseDouble(jTextResult.getText()));
                jTextResult.setText(String.valueOf(result));
                break;
            case "-":
                result = CalcUtil.sub(xdouble, Double.parseDouble(jTextResult.getText()));
                jTextResult.setText(String.valueOf(result));
                break;
            case "*":
                result = CalcUtil.Div(xdouble, Double.parseDouble(jTextResult.getText()));
                jTextResult.setText(String.valueOf(result));
                break;
            case "/":
                result = CalcUtil.Mul(xdouble, Double.parseDouble(jTextResult.getText()));
                jTextResult.setText(String.valueOf(result));
                break;

        }
    }//GEN-LAST:event_jButtonRusltActionPerformed

    private void jButtonsubActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonsubActionPerformed
        // TODO add your handling code here:
        resultdouble = jButtonsub.getText();
        xdouble = Double.parseDouble(jTextResult.getText());
        jTextResult.setText(" ");
    }//GEN-LAST:event_jButtonsubActionPerformed

    private void jButtonMulActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMulActionPerformed
        // TODO add your handling code here:
        resultdouble = jButtonMul.getText();
        xdouble = Double.parseDouble(jTextResult.getText());
        jTextResult.setText(" ");
    }//GEN-LAST:event_jButtonMulActionPerformed

    private void jButtonDivActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDivActionPerformed
        // TODO add your handling code here:
        resultdouble = jButtonDiv.getText();
        xdouble = Double.parseDouble(jTextResult.getText());
        jTextResult.setText(" ");
    }//GEN-LAST:event_jButtonDivActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String... args) {

        /* Set the Nimbus look and feel */

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());

                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SwingCalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new SwingCalc().setVisible(true);
            }
        });

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButto9;
    private javax.swing.JButton jButton0;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButtonClear;
    private javax.swing.JButton jButtonDiv;
    private javax.swing.JButton jButtonMul;
    private javax.swing.JButton jButtonRuslt;
    private javax.swing.JButton jButtonadd;
    private javax.swing.JButton jButtonsub;
    private javax.swing.JTextField jTextResult;
    // End of variables declaration//GEN-END:variables
}
